clear all

********************************************************************************
********************************************************************************
**** When Can We Trust Regression Discontinuity Design Estimates from Close ****
*************** Elections? Evidence from Experimental Benchmarks ***************
********************************************************************************
********************************************************************************

* This file produces Table OA5 in Online Appendix C of De Magalhaes et al. 
* (Political Analysis).

cd "$dir"
use "$dir/data/personal_incumbency_advantage.dta", clear

********************************************************************************

est clear

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(0) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(0) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(0) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(1) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(1) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(1) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(2) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(2) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(2) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(3) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(3) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(3) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(4) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) p(4) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Brazil", c(0) rho(1) p(4) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

esttab est* using "$dir/tables/table_OA5.tex", replace noomitted nobaselevels booktabs mlabels(none) ///
	mgroups("\textit{p} = 0" "\textit{p} = 1" "\textit{p} = 2" "\textit{p} = 3" "\textit{p} = 4", pattern(1 1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) ) ///
	compress lines nostar label ///
	b(%9.3f) ci(%9.3f) stats(obs bw amse1 amse2, labels("\textit{N}" "Bandwidth" "AMSE (conventional)" "AMSE (robust)") ///
	fmt(0 2 5 5)) keep(Conventional Robust) ///
	nodepvars nomtitle prehead(\begin{tabular}{l*{6}{c}} \toprule) refcat(Conventional "\textbf{Panel A:} Brazil", nolabel) ///
	postfoot(" ")

est clear

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(0) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(0) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(0) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(1) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(1) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(1) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(2) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(2) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(2) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(3) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(3) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(3) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(4) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) p(4) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Colombia", c(0) rho(1) p(4) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

esttab est* using "$dir/tables/table_OA5.tex", append noomitted nonumbers nobaselevels booktabs mlabels(none) ///
	compress lines nostar label ///
	b(%9.3f) ci(%9.3f) stats(obs bw amse1 amse2, labels("\textit{N}" "Bandwidth" "AMSE (conventional)" "AMSE (robust)") ///
	fmt(0 2 5 5)) keep(Conventional Robust) ///
	nodepvars nomtitle prehead("") refcat(Conventional "\textbf{Panel B:} Colombia", nolabel) ///
	postfoot(" ")
	
est clear

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(0) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(0) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(0) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(1) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(1) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(1) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(2) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(2) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(2) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(3) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(3) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(3) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(4) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) p(4) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Denmark", c(0) rho(1) p(4) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

esttab est* using "$dir/tables/table_OA5.tex", append noomitted nonumbers nobaselevels booktabs mlabels(none) ///
	compress lines nostar label ///
	b(%9.3f) ci(%9.3f) stats(obs bw amse1 amse2, labels("\textit{N}" "Bandwidth" "AMSE (conventional)" "AMSE (robust)") ///
	fmt(0 2 5 5)) keep(Conventional Robust) ///
	nodepvars nomtitle prehead("") refcat(Conventional "\textbf{Panel C:} Denmark", nolabel) ///
	postfoot(" ")
	
est clear

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(0) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(0) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(0) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(1) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(1) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(1) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(2) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(2) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(2) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(3) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(3) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(3) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

rdbwselect runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(4) vce(cluster constituency) kernel(uniform) bwselect(cerrd)
local h =  e(h_cerrd)
local b = e(b_cerrd)

rdmse runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) p(4) h(`h') b(`h')
local amse1=r(amse_cl)
local amse2=r(amse_bc)
eststo: rdrobust runningnextelection rv if rv!=0 & rv!=. & country=="Finland", c(0) rho(1) p(4) all vce(cluster constituency) kernel(uniform) bwselect(cerrd)
estadd scalar bw = `h'
estadd scalar obs = e(N_h_l) + e(N_h_r)
estadd scalar amse1=`amse1'
estadd scalar amse2=`amse2'

esttab est* using "$dir/tables/table_OA5.tex", append nonumbers noomitted nobaselevels booktabs mlabels(none) ///
	compress lines nostar label ///
	b(%9.3f) ci(%9.3f) stats(obs bw amse1 amse2, labels("\textit{N}" "Bandwidth" "AMSE (conventional)" "AMSE (robust)") ///
	fmt(0 2 5 5)) keep(Conventional Robust) ///
	nodepvars nomtitle prehead(" ") refcat(Conventional "\textbf{Panel D:} Finland", nolabel) ///
	postfoot(\bottomrule \end{tabular})
	
est clear
